<include file="Public:header" />
<include file="Public:leftside" />
<style type="text/css">
	.modal {
	    height: 600px;
	   
	}
	.modal-infp-style {
		width: 90%;
		margin: 10px auto;
	}
	
	.modal-infp-style table {
		width: 100%;
	}
	
	.modal-infp-style table tr td {
		border: 1px solid #e6e6e6;
		padding: 8px;
	}
	
	a:hover {
		cursor: pointer;
	}
	.panel .table td{
		vertical-align: center;
	}
.pagination a{display: block;float: left;border-bottom-left-radius: 3px;border-top-left-radius: 3px;padding: 5px 10px;font-size: 12px;font-weight: 500;border-radius: 2px;}
.pagination span{display: block;float: left;border-bottom-left-radius: 3px;border-top-left-radius: 3px;background-color: #fafafa;border: 1px solid #dddddd;padding: 5px 10px;font-size: 12px;font-weight: 500;border-radius: 2px;}

</style>
<div class="main-content">
	<div class="breadcrumbs breadcrumbs-fixed" id="breadcrumbs">
		<ul class="breadcrumb">
			<li> <i class="icon-home home-icon"></i>
				<a href="/">首页</a>
			</li>
			<li class="active">会员管理</li>
		</ul>
	</div>
	<section class="scrollable wrapper">
		<!--<div class="row panel-body" style="padding-top:0px;">
			<a href="http://test.niushop.com/index.php/platform/member/memberlist.html" class="btn btn-sm btn-primary">会员列表</a>
			<a href="http://test.niushop.com/index.php/platform/member/memberlevellist.html" class="btn btn-sm btn-default">会员等级</a>
			<a href="http://test.niushop.com/index.php/platform/member/usercommissionwithdrawlist.html" class="btn btn-sm btn-default">会员提现</a>
			<a href="http://test.niushop.com/index.php/platform/member/pointlist.html" class="btn btn-sm btn-default">积分管理</a>
			<a href="http://test.niushop.com/index.php/platform/member/accountlist.html" class="btn btn-sm btn-default">余额管理</a>
			<a href="http://test.niushop.com/index.php/platform/member/weixinfanslist.html" class="btn btn-sm btn-default">粉丝列表</a>
		</div>-->
		<!-- 操作提示  start -->
		<!-- 操作提示  end -->
		<form action="__CONTROLLER__/index/" method="get">
		<div class="row padder-v">
			<div class="col-sm-9" style="width:65%;">
				<a  class="btn btn-sm btn-primary" href="{:U('Member/addmember')}"><i class="fa fa-plus"></i> 添加会员 </a>
			</div>
			<div class="col-sm-2">
				<input type="text" name="phone" value="<?=$_GET['phone']?>" class="form-control input-sm" placeholder="请输入用户手机号"/>
			</div>
			<div class="col-sm-2" >
				<button class="btn btn-sm btn-default" type="submit" >搜索</button>
				<a href="{:U('Member/index')}" class="btn btn btn-info btn-sm" >清空</a>
			</div>
		</div>
		</form>
		<section class="panel panel-default">
			<div class="table-responsive">
				<table class="table table-striped b-t b-light text-sm">
					<thead>
						<tr>
							<th class="center">会员卡号</th>
							<th class="center">姓名</th>
							<th class="center">手机号</th>
							<th class="center">会员等级</th>
							<th class="center">会员积分</th>
							<th class="center">账户余额</th>
							<!--<th class="center">累计消费</th>-->
							<th class="center">有效期</th>
							<th class="center">状态</th>
							<th class="center">操作</th>
						</tr>
					</thead>
					<tbody id="list">
						<foreach name="member_list" item="v">
							<tr align="center">

								<td class="tal">{$v.memberId}</td>
								<td class="tal">{$v.username}</td>
								<td class="tal">{$v.phone}</td>
								<td class="tal">{$v.gradeName}</td>
								<td class="tal">{$v.integral}</td>
								<td class="tal">¥{$v.money}</td>
								<!--<td class="tal">¥{$v.total_expense}</td>-->
								<php>
									 $v['start_time']=date('Y-m-d H:i:s',$v['start_time']);
									 $v['end_time']=date('Y-m-d H:i:s',$v['end_time']);
								</php>
								<td class="tal">{$v['start_time']}--{$v['end_time']}</td>
								<td style="color:green;">
									<eq name="v.status" value="1">启用</eq>
									<eq name="v.status" value="0">锁定</eq>
								</td>
								<td>
									<notempty name="v['phone']">
										<a onclick="integral_change({$v.id},{$v.integral})">积分变动</a><br>
										<a onclick="grade_change({$v.id},{$v.grade})">等级变更</a><br>
                                        <a onclick="balance_change({$v.id},{$v.money})">充值</a>
									</notempty>
							</tr>
						</foreach>
					</tbody>
				</table>
			</div>

			<footer class="panel-footer">
				<div class="row" id="page">
				<div class="col-sm-2 text-center">
						<small class="text-muted inline m-tb-8">总计 <span id="total_count_num">{$count}</span>个记录</small>
					</div>
					<div class="col-sm-5 text-right text-center-xs">
						<ul class="pagination pagination-sm m-t-none m-b-none">
							{$page}
						</ul>
					</div>
				</div>
			</footer>

		</section>

		<script type="text/javascript">
			//余额充值
			function balance_change(member_id, balance) {
				$("#recharge").modal("show");
				$("#member_id").val(member_id);
				$("#current_balance").text(balance);
			}
			//充值
			function recharge(type) {
				var id = $("#member_id").val();
				var num = $("#balance").val();
				var current_balance = $("#current_balance").text();
				var balance = (parseInt(current_balance) + parseInt(num));
				if(num == '') {
					layer.msg('余额不能为空！')
					return false;
				}
				var text = $("#remark_balance").val();
				if(parseInt(balance) < 0) {
					layer.msg('余额不能为负数！')
					return false;
				}
				$.ajax({
					type: "post",
					url: "{:U('Member/recharge')}",
					data: {
						"id": id,
						"type": type,
						"num": num,
						"text": text
					},
					success: function(data) {
                        json= JSON.parse(data);
                        if(json.status == 0) {
                            layer.msg('无数据更新！')
                        }
                        if(json.status == 1) {
                            layer.msg('修改成功！');
                            setTimeout("location.reload()",1000);
                        }
					}
				});
			}
            //积分变动
            function integral_change(member_id,integral) {
                $("#integral_change").modal("show");
                $("#member_id").val(member_id);
                $("#current_integral").text(integral);
            }
            //积分变动
            function integral_modify() {

                var id = $("#member_id").val();
                var num = $("#integral").val();
                var current_integral = $("#current_integral").text();
                var integral = (parseInt(current_integral) + parseInt(num));
                if(num == '') {
                    layer.msg('积分不能为空！')
                    return false;
                }
                var text = $("#remark_integral").val();
                if(parseInt(integral) < 0) {
                    layer.msg('积分不能为负数！')
                    return false;
                }

                $.ajax({
                    type: "post",
                    url: "{:U('Member/integral_modify')}",
                    data: {
                        "id": id,
                        "type": type,
                        "num": num,
                        "text": text
                    },
                    success: function(data) {
                        json= JSON.parse(data);
                        if(json.status == 0) {
                            layer.msg('无数据更新！')
                        }
                        if(json.status == 1) {
                            layer.msg('修改成功！');
                            setTimeout("location.reload()",1000);
                        }
                    }
                });
            }
            //等级变更
            function grade_change(member_id,grade) {
                $("#grade_change").modal("show");
                $("#member_id").val(member_id);
                $("#grade").val(grade);
            }
            //等级变更
            function grade_modify() {
                var id = $("#member_id").val();
                var grade = $("#grade").val();
                if(grade == '') {
                    layer.msg('等级不能为空！')
                    return false;
                }
                $.ajax({
                    type: "post",
                    url: "{:U('Member/grade_modify')}",
                    data: {
                        "id": id,
                        "grade": grade,
                    },
                    success: function(data) {
                        json= JSON.parse(data);
                        if(json.status == 0) {
                            layer.msg('无数据更新！')
                        }
                        if(json.status == 1) {
                            layer.msg('修改成功！');
                            setTimeout("location.reload()",1000);
                        }
                    }
                });
            }
		</script>
		<!-- 余额调整 -->
		<div class="modal" id="recharge" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
						<h4 class="modal-title">调整余额</h4>
					</div>
					<div class="modal-body">
						<div class="modal-infp-style">
							<table>
								<tbody>
									<tr>
										<td>当前余额</td>
										<td colspan="3" id="current_balance"></td>
									</tr>
									<tr>
										<td>调整金额</td>
										<td colspan="3"><input type="number" id="balance" class="balance">增加或减少</td>
									</tr>
									<tr>
										<td>备注</td>
										<td colspan="3"><textarea id="remark_balance"></textarea></td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>

					<div class="modal-footer">
						<input type="hidden" id="member_id">
						<button class="btn btn-info" onclick="recharge(2)" id="butSubmit" data-dismiss="modal" aria-hidden="true" style="display:inline-block;">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>

		</div>

		<!-- 积分变动-->
        <div class="modal" id="integral_change" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">积分变动</h4>
                    </div>
                    <div class="modal-body">
                        <div class="modal-infp-style">
                            <table>
                                <tbody>
                                <tr>
                                    <td>当前积分</td>
                                    <td colspan="3" id="current_integral"></td>
                                </tr>
                                <tr>
                                    <td>调整积分</td>
                                    <td colspan="3"><input type="number" id="integral" class="balance">增加或减少</td>
                                </tr>
                                <tr>
                                    <td>备注</td>
                                    <td colspan="3"><textarea id="remark_integral"></textarea></td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <input type="hidden" id="member_id">
                        <button class="btn btn-info" onclick="integral_modify()" id="butSubmit" data-dismiss="modal" aria-hidden="true" style="display:inline-block;">保存</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </div>
            </div>

        </div>
		<!--<input type="hidden" id="modify_uid">-->

        <!-- 等级变更-->
        <div class="modal" id="grade_change" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">等级变更</h4>
                    </div>
                    <div class="modal-body">
                        <td class="modal-infp-style">
                            <table>
                                <tbody>
                                <tr>
                                    <td>会员等级*</td>
                                    <td  colspan="3">
                                        <select  name="grade" id="grade">
                                            <foreach name="grade_list" item="v">
                                            <option value="{$v.id}">{$v.gradeName}</option>
                                            </foreach>
                                        </select>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>

                    <div class="modal-footer">
                        <input type="hidden" id="member_id">
                        <button class="btn btn-info" onclick="grade_modify()" id="butSubmit" data-dismiss="modal" aria-hidden="true" style="display:inline-block;">保存</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </div>
            </div>

        </div>

	</section>
</div>

<include file="Public:footer" />